package mscloud.router;

import mscloud.handler.ValidateCodeObtainHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

/**
 * @Datetime: 2025年07月23日17:38
 * @Author: Eleven52AC
 * @Description: webFlux路由配置类
 */
@Configuration
public class WebFluxRouterConfiguration {

    private final ValidateCodeObtainHandler validateCodeObtainHandler;

    public WebFluxRouterConfiguration(ValidateCodeObtainHandler validateCodeObtainHandler) {
        this.validateCodeObtainHandler = validateCodeObtainHandler;
    }

    @Bean
    public RouterFunction<ServerResponse> routerFunctions() {
        return RouterFunctions.route(
                RequestPredicates.GET("/code").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)),
                validateCodeObtainHandler);
    }
}
